package com.hopu.blb_erp.service.impl;

import com.hopu.blb_erp.entity.Order2;
import com.hopu.blb_erp.entity.Order2ToBeProduced;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.PageEntityP;
import com.hopu.blb_erp.mapper.Order2Mapper;
import com.hopu.blb_erp.service.IOrder2Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author A-Zhang
 * @since 2021-11-18
 */
@Service
public class Order2ServiceImpl extends ServiceImpl<Order2Mapper, Order2> implements IOrder2Service {
    @Autowired
    private Order2Mapper order2Mapper;
    @Override
    public PageEntity<Order2ToBeProduced> findPage(int current, int pageSize, String orderId, String dealTime) {
        int count=order2Mapper.selectOrderCount(orderId,dealTime);

        List<Order2ToBeProduced> order2ToBeProduceds = order2Mapper.selectLimit((current - 1) * pageSize, pageSize, orderId, dealTime);

        PageEntity<Order2ToBeProduced> objectPageEntity = new PageEntity<>();
        objectPageEntity.setCount(count);
        objectPageEntity.setCurrent(current);
        objectPageEntity.setData(order2ToBeProduceds);
        return objectPageEntity;
    }
    @Override
    public Integer findCount() {
        return order2Mapper.selectAllCount();
    }

    @Override
    public PageEntity<Order2> findPage(Integer current, Integer pageSize) {
        Integer count = order2Mapper.selectAllCount();
        List<Order2> orders = order2Mapper.selectPage((current - 1) * pageSize, pageSize);
        PageEntity<Order2> orderPageEntity = new PageEntity<>();
        orderPageEntity.setData(orders);
        orderPageEntity.setCurrent(current);
        orderPageEntity.setCount(count);
        return orderPageEntity;
    }

    @Override
    public void addOrder2(Order2 Order2) {
        order2Mapper.insertOrder2(Order2);
    }

    @Override
    public void removeOrder2(List<Integer> ids) {
        order2Mapper.deleteOrder2(ids);
    }

    @Override
    public Order2 findOrder2ByOrderId(String orderId) {
        return order2Mapper.selectOrder2ByOrderId(orderId);
    }

    @Override
    public void modifyOrder2(String orderId) {
        order2Mapper.updateOrder2(orderId);
    }

    @Override
    public void modifyZumaid(String orderId, String zumaid) {
        order2Mapper.updateZumaid(orderId,zumaid);
    }


//
    @Override
    public PageEntityP<Order2> findPPage(Integer current) {
        //查询总数
        int count = order2Mapper.selectPCount();
        //显示出来的页数
        int pageCount = count % PageEntityP.PAGE_SIZE == 0 ? count / PageEntityP.PAGE_SIZE :PageEntityP.PAGE_SIZE + 1;
        //使用limit查询分页
        List<Order2> order2s = order2Mapper.selectPPage((current - 1) * PageEntityP.PAGE_SIZE, PageEntityP.PAGE_SIZE);
        return new PageEntityP<>(order2s,count,current,pageCount);
    }
}
